package com.fenghongzhang.day002;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;

public class PopupMenuActivity extends AppCompatActivity {
    private TextView one;
    private TextView two;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_menu);
       
        one = (TextView) findViewById(R.id.one);
        two = (TextView) findViewById(R.id.two);
        
        

    }

    public void one(View view) {
        //1,上下文. 2,要显示在哪个组件的下方.
        PopupMenu popupMenu = new PopupMenu(this, two);
        
        //加载菜单布局
        popupMenu.inflate(R.menu.menu2);

        //布局中的菜单点击事件.
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                int itemId = item.getItemId();
                switch (itemId){
                    case R.id.red2:
                        Toast.makeText(PopupMenuActivity.this, "hehe", Toast.LENGTH_SHORT).show();
                        break;
                }
                return false;
            }
        });
        //显示.
        popupMenu.show();

    }
}
